package org.elephas.webapp.frontend.component.links;

import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.markup.html.panel.Panel;
import org.elephas.webapp.application.ElephasSession;
import org.elephas.webapp.frontend.component.LoginFormPanel;
import org.elephas.webapp.frontend.jquery.SimpleModal;

public class LoginLinkPanel extends Panel {

	private static final long serialVersionUID = 1L;

	public LoginLinkPanel(String id) {
		super(id);
		final SimpleModal loginModal = new SimpleModal("loginModal") {
			private static final long serialVersionUID = 1L;

			@Override
			protected Panel newPanel(String id) {
				return new LoginFormPanel(id);
			}
		};
		add(loginModal);
		add(new AjaxLink("loginLink") {
			private static final long serialVersionUID = 1L;

			@Override
			public void onClick(AjaxRequestTarget target) {
				loginModal.show(target);
			}
		});
	}
	
	@Override
	public boolean isVisible() {
		return !ElephasSession.get().isSignedIn();
	}
}
